package test;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

import javax.faces.context.FacesContext;
import javax.persistence.EntityManager;

import shake.annotation.Component;
import shake.annotation.PageScoped;
import shake.annotation.RedirectScoped;
import shake.context.SeriarizableObject;

import com.google.inject.Inject;
import com.google.inject.Provider;

@RedirectScoped
@Component(name = "login")
public class Login {

	@Inject
	Provider<FacesContext> context;

	@PageScoped
	static public class P extends SeriarizableObject {

		public P() {
			System.out.println("create P");
			System.out.println(this.getClass());
		}

		String value = "aaa";
	}

	@Inject
	P p;

	@Inject
	EntityManager manager;

	public String invoke(String aaa) {
		System.out.println("invoke " + aaa + "\t" + p.value);
		value = aaa;
		p.value = aaa;
		// System.out.println(p.getClass());
		System.out.println(manager);
		System.out.println(context.get());
		return aaa;
	}

	String value = "testValue";

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	// @Singleton
	// @Startup
	// @Component
	// static class Navigation implements NavigationRule {
	// @Inject
	// public Navigation(NavigationRuleRegistry registry) {
	// registry.add(this);
	// }
	//
	// public boolean rule(NavigationManager manager, MethodExpression method,
	// Object returnValue, boolean isPageAction) {
	// // System.out.println(method.getExpressionString());
	// // System.out.println(returnValue);
	// // if (method.getExpressionString().equals("${login.invoke(bbbb)}"))
	// // {
	// // manager.setRenderPath("/Login.jsp");
	// // manager.setRender(true);
	// // return true;
	// // }
	// return false;
	// }
	//
	// }

	public static void main(String[] args) throws IOException {

		P p = new P();

		ObjectOutputStream oos = new ObjectOutputStream(
				new ByteArrayOutputStream());
		oos.writeObject(p);
		oos.close();
	}
}
